#include "smg.h"
#include "intrins.h"


void Delay_ms(int xms)		//15单片机延时函数@11.0592MHz
{
	unsigned char i, j;		
	while(xms--)
	{
		_nop_();
		_nop_();
		_nop_();
		i = 11;
		j = 190;
		do
		{
			while (--j);
		} while (--i);
	}	
}

/*共阳极码表 ABCDEF都是大写*/
unsigned char wei[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0x88, 0x80, 0xC6, 0xC0, 0x86, 0x8E, 0xBF, 0xFF};
					   //0     1     2     3     4     5     6     7     8     9     A     B     C     D     E     F     -    灭

	
void SMG_Diaplay(void)
{
	//第1个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x01;	//选中第1个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[1];
	Delay_ms(1);
	
	//第2个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x02;	//选中第2个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[2];
	Delay_ms(1);
	
	//第3个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x04;	//选中第3个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[3];
	Delay_ms(1);
	
	//第4个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x08;	//选中第4个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[4];
	Delay_ms(1);
	
	//第5个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x10;	//选中第5个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[5];
	Delay_ms(1);
	
	//第6个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x20;	//选中第6个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[6];
	Delay_ms(1);
	
	//第7个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x40;	//选中第7个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[7];
	Delay_ms(1);
	
	//第8个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x80;	//选中第8个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[8];
	Delay_ms(1);
}
	
void DJS_Show(unsigned char bai, unsigned char shi, unsigned char ge)
{
	//第6个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x20;	//选中第6个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[bai];	//显示百位
	Delay_ms(1);
	
	//第7个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x40;	//选中第7个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[shi];	//显示十位
	Delay_ms(1);
	
	//第8个数码管
	P2 = 0xC0;	//Y6=0;Y6C=1; 使能锁存器U8     P27 = 1; P26 = 1; P25 = 0;
	P0 = 0x80;	//选中第8个数码管
	P2 = 0xFF;	//Y7=0;Y7C=1; 使能锁存器U7     P27 = 1; P26 = 1; P25 = 1;
	P0 = wei[ge];	//显示个位
	Delay_ms(1);
}	

